<template>
  <view class="preference">
    <view class="margin-box">
      <view class="center-box" v-if="computedShowData.poiList.length > 0">
        <view class="pre-flex-box">
          <block
            v-for="(item, index) in computedShowData.poiList"
            :key="'themes' + index"
            :data-spmCntSuffix="'ChatAiPage.poiTag@1.tag'"
            :data-custom="index + 1"
            :data-spm="item"
          >
            <view
              v-if="index < 8 || open"
              class="flex-box-item omit1"
              :class="{ active: item.checked }"
              @click="themesClick(index)"
              >{{ item.poiName }}</view
            >
          </block>
          <view class="open" @click="openMore"
            >{{ open ? "收起" : "展开全部"
            }}<uni-icons
              :type="open ? 'top' : 'bottom'"
              color="#B5B5D2"
              size="14"
            ></uni-icons>
          </view>
        </view>
        <view class="sure-box" 
          @click="sureClick"
          :data-spmCntSuffix="'ChatAiPage.poiTag@2.confirm'"
          :data-custom="1"
          :data-spm="1"
        >确认选择</view>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  props: {
    showData: {
      type: Object,
    },
  },
  computed: {
    computedShowData: {
      get() {
        const newObj = this.showData;
        let poiList = newObj.poiList;
        console.log("newObj", newObj);
        for (var i = 0; i < poiList.length; i++) {
          poiList[i].checked = false;
        }
        newObj.poiList = poiList;
        return newObj;
      },
      set() {},
    },
  },
  data() {
    return {
      chosePoiList: [],
      open: false,
    };
  },
  watch: {},
  methods: {
    themesClick(index) {
      let obj = this.computedShowData;
      console.log("obj", obj);
      obj.poiList[index].checked = !obj.poiList[index].checked;
      let arr = [];
      obj.poiList.map((item) => {
        if (item.checked) {
          arr.push(item);
        }
      });
      this.chosePoiList = arr;
      this.$forceUpdate();
    },
    sureClick() {
      if (this.chosePoiList.length <= 0) {
        uni.showToast({
          title: "请填选择景点",
          icon: "none",
        });
      } else {
        let params = {
          favoritePoiList: this.chosePoiList,
          type: 31,
        };
        this.$emit("sureClick", params);
      }
    },
    openMore() {
      this.open = !this.open;
    },
  },
};
</script>

<style scoped lang="scss">
.preference {
  .margin-box {
    padding: 0 24rpx;
    margin: 30rpx auto 0 auto;
    .pre-flex-box {
      display: flex;
      flex-wrap: wrap;
      justify-content: space-between;
      .flex-box-item {
        width: 218rpx;
        height: 58rpx;
        background: #FFFFFF;
        border-radius: 29rpx;
        margin: 0 0 15rpx 0;
        color: $sl-color-dark-grey;
        font-size: 24rpx;
        text-align: center;
        line-height: 58rpx;
        padding: 0 26rpx;
      }
      .flex-box-item.active {
        color: $sl-color-blue;
        background: $sl-bg-color-grey;
      }
      .open {
        display: flex;
        align-items: center;
        justify-content: center;
        color: $sl-color-light-grey;
        font-size: 24rpx;
        width: 100%;
        padding-top: 11rpx;
      }
    }

    .sure-box {
      height: 68rpx;
      border-radius: 34rpx;
      background: $sl-color-light-blue;
      line-height: 68rpx;
      text-align: center;
      color: #fff;
      font-size: 28rpx;
      margin: 26rpx auto 0 auto;
      font-weight: 600;

    }
  }
}

</style>
